﻿using System;
using System.Collections.ObjectModel;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Jaws.Core.Web.Entities;
using Jaws.Core.Web.Entities.Pages;
using Jaws.Core.Web.Entities.Roles;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Jaws.Tests
{
    /// <summary>
    /// Summary description for EntityContructors
    /// </summary>
    [TestClass]
    public class EntityContructors
    {

        /// <summary>
        ///A test for Page Constructor
        ///</summary>
        [TestMethod()]
        public void PageConstructorTest()
        {
            var target = new Page
                              {
                                  Title = "New Page",
                                  Description = "this des",
                                  Keywords = "keys",
                                  Slug = "new page",
                                  Parent = Guid.NewGuid(),
                                  IsHomePage = true,
                                  ShowInList = true
                              };
            target.Save();
            Assert.IsFalse(target.IsChanged);
        }

        [TestMethod]
        public void Roles()
        {
            var administratorRole = new Role
                            {
                                Name = "Administrators",
                                Users = new List<string>(new List<string> { "Admin", "rclarkson" })
                            };

            var editorRole = new Role
            {
                Name = "Editors",
                Users = new List<string>(new List<string> { "Admin", "rclarkson" })
            };

            var roleCollection = new RoleCollection(){administratorRole, editorRole};
            roleCollection.Save();
            Assert.IsFalse(roleCollection.IsChanged);
        }

        [TestMethod]
        public void LoadRoles()
        {
            RoleCollection roleCollection = XmlCollectionBase<RoleCollection, Role>.Load();
            Assert.IsTrue(roleCollection.Count > 0);
        }

        [TestMethod]
        public void DeleteARole()
        {
            int initial = 0;
            int final = 0;
            RoleCollection roleCollection = XmlCollectionBase<RoleCollection, Role>.Load();
            initial = roleCollection.Count;
            roleCollection[initial - 1].Delete();
            roleCollection.Save();
            final = roleCollection.Count;
            Assert.IsFalse(initial != final);
        }


        /// <summary>
        ///A test for Page Constructor
        ///</summary>
        [TestMethod()]
        public void ParentPageTest()
        {
            PageCollection pageCollection= XmlCollectionBase<PageCollection, Page>.Load();

            var target = new Page
            {
                Title = "New Page",
                Description = "this des",
                Keywords = "keys",
                Slug = "new page",
                Parent = pageCollection[0].Id,
                IsHomePage = true,
                ShowInList = true
            };

            target.Save();
            Assert.IsFalse(target.IsChanged);
        }
    }
}
